'use client'

import { useEffect } from 'react'
import { useParams, useRouter } from 'next/navigation'
import { AppLayout } from '@/components/layout/AppLayout'
import { SheetPage } from '@/components/pages/SheetPage'
import { useAuth } from '@/contexts/AuthContext'

export default function SheetPageRoute() {
  const params = useParams()
  const router = useRouter()
  const { user, loading: authLoading } = useAuth()
  const sheetId = params.id as string

  useEffect(() => {
    if (!authLoading && !user) {
      router.push('/')
    }
  }, [authLoading, user, router])

  if (authLoading) {
    return null
  }

  if (!user) {
    return null
  }

  return (
    <AppLayout>
      <SheetPage
        sheetId={sheetId}
        onBack={() => router.push('/')}
      />
    </AppLayout>
  )
}
